<?php
/**
 * Created by PhpStorm.
 * User: raoho
 * Date: 2018/1/3
 * Time: 18:32
 */

namespace Xcx\Controller;

use Think\Controller;
use Xcx\Common\ErrorCode;
use Xcx\Model\LoginModel;

header("Content-type: text/html; charset=utf-8");
class CommonController extends Controller{
    public $uid;

    /**
     * 检查用户是否登陆
     */
    public function checkLogin()
    {
        $session3rd = $_SERVER['HTTP_SESSION3RD'];
//        $session3rd = '156484561548';//$_SERVER['HTTP_SESSION3RD'];

        if ($session3rd == '' || $session3rd == null) {
            $this->ajaxReturn(array('code'=>ErrorCode::$NoSession,'errMsg'=>'session3rd丢失'));
        }

        //查询用户uid
        $LoginModel = new LoginModel();
        $user = $LoginModel->getLoginSession($session3rd);
        $uid = $user['uid'];
        $_SESSION['userInfo']['uid'] = $uid;

        if ($uid != null && $uid != '') {
            $this->uid = $uid;
        } else {
            $this->ajaxReturn(array('code'=>ErrorCode::$NoLogin,'errMsg'=>'未登录'));
        }
    }
}